
/*
* 贷后管理首页 台账 js
*
* */
var layer;
var table;
var basePath;
var vm;
var sendServer;
window.layinit(function (htConfig) {
    var _htConfig = htConfig;
    basePath = _htConfig.coreBasePath;
    uiBasePath = _htConfig.uiBasePath;
    vm = new Vue({
        el: '#app',
        data: {
            editSalary:false,
            loading: false,
            exporting: false,//导出标志位
            searchForm: {
                paydayTimeYear: '',  //发薪时间
                sendType: '',
                sendState: '',  //发送状态
                confirmState: '' ,
                sendServer:'1',
                key: ''  //关键字

            },
            salaryTableNameList: [],  // 工资表名列表
            personAmount:'0',
            notSend:'0',
            sended:'0',
            sendFail:'0',
            confirmed:'0',
            notConfirm:'0',
            emailForm:{
                sendType:'',
                sendServer:1,
                endDate:'',
                batchCode:'',
                flag:'',
                sendBaseList:[]
            },
            sendBaseDto:{
                email:'',
                jobCode:'',
                name:''
            }

        },

        methods: {
            //重载表格
            toLoading: function () {
                if (table == null) {
                    return;
                }
                var self = this;
                self.loading = true;
                table.reload('listTable', {
                    where: {

                        dataTime: self.searchForm.paydayTimeYear,  //发薪年份
                        confirmState: self.searchForm.confirmState,  //确认状态
                        sendState: self.searchForm.sendState,  //发送状态
                        sendType: self.searchForm.sendType,
                        sendServer: self.searchForm.sendServer,
                        key: self.searchForm.key  //关键字
                    }
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            },
            handleReset: function (name) { // 重置表单
                vm.searchForm.paydayTimeYear = '';
                vm.searchForm.confirmState = '';
                vm.searchForm.sendState = '';
                vm.searchForm.sendType = '';
                vm.searchForm.key = '';

                vm.toLoading();
            },
            init: function () {
                var self = this;
                //使用layerUI的表格组件
                layui.use(['layer', 'table', 'ht_ajax', 'ht_auth', 'ht_config'], function () {
                    layer = layui.layer;
                    table = layui.table;
                    //执行渲染
                    table.render({
                        elem: '#listTable' //指定原始表格元素选择器（推荐id选择器）
                        , id: 'listTable'
                        , cols: [[
                             {field: 'batchCode', title: '批次号', width:100, fixed: 'left', align:'center'}
                            ,{field: 'jobCode', title: '工号', width:100, fixed: 'left', align:'center'}
                            ,{field: 'sendServer', title: '服务类型', width:100, fixed: 'left', align:'center',
                                templet: function (d) {
                                    var content = "";
                                    if (d.sendServer == "1") {
                                        content = '邮件'
                                    } else if (d.sendServer == "2") {
                                        content = '钉钉'
                                    }
                                    return content
                                }
                            }
                            ,{field: 'name', title: '姓名', width:250, align:'center'}
                            ,{field: 'sendType', title: '发送类型', width:100, align:'center',templet: '#sendTypeTpl'}
                            ,{field: 'sendState', title: '邮件发送状态', width:150, align:'center',templet: '#sendStateTpl'}
                            ,{field: 'confirmState', title: '邮件确认状态', width:150, align:'center',templet: '#confirmStateTpl'}
                            ,{field: 'createTime', title: '邮件发送时间', width:200, align:'center'}
                            ,{title: '操作',fixed: 'right', width: 250, align:'center', toolbar: '#barTools'}
                        ]], //设置表头
                        url: basePath + 'msg/list',

                        page: true,
                        done: function (res, curr, count) {
                            //数据渲染完的回调。你可以借此做一些其它的操作
                            //如果是异步请求数据方式，res即为你接口返回的信息。
                            //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                            self.loading = false;
                        }
                    });

                    table.on('tool(listTable)', function (obj) {
                        var selectedRowInfo = obj.data;
                        var jobCode = selectedRowInfo.jobCode;
                        var batchCode = selectedRowInfo.batchCode;
                        var sendType = selectedRowInfo.sendType;
                        var sendServer = selectedRowInfo.sendServer;
                        var endDate = selectedRowInfo.checkEndTime;
                        if(obj.event === 'resend'){
                            layer.confirm('确定重发?', function(index){
                                self.confirmSend(batchCode,jobCode,endDate,sendType,sendServer);
                                layer.close(index);
                            });

                        }
                        if(obj.event === 'withdraw'){
                            layer.confirm('确定撤回?', function(index){
                                self.cancelEmail(2,jobCode,batchCode,sendType,sendServer);
                                layer.close(index);
                            });

                        }
                    });
                })
            },
            confirmSend:function (batchCode,jobCode,endDate,sendType,sendServer) {
                var self = this;
                self.emailForm.batchCode = batchCode;
                self.emailForm.sendType=sendType;
                self.emailForm.sendServer=[sendServer];
                self.emailForm.flag=2;

                self.sendBaseDto.jobCode=jobCode;
                self.emailForm.sendBaseList=[];
                self.emailForm.sendBaseList.push(self.sendBaseDto);

                var url = basePath + "sendinfo/sendSalaryEmail";
                var data = JSON.stringify(self.emailForm);
                console.log("data========>>>>>>",data);
                $.ajax({
                    type: "POST",
                    url: url,
                    contentType: "application/json; charset=utf-8",
                    async: false,
                    data:data ,
                    dataType: "json",
                    success: function (result) {
                        if (result.returnCode == "0") {
                            layer.msg("发送成功");
                            self.toLoading();
                        }else {
                            layer.msg(result.msg);
                            self.toLoading();
                        }
                    },
                    error:function (result) {
                        debugger;
                        layer.msg("发送失败："+result.msg);
                        self.toLoading();
                    }

                });

            },
            cancelEmail:function (type,jobCode,batchCode,sendType,sendServer) {
                var self = this;
                var url = basePath + "sendinfo/sendRecall?sendType="+sendType+"&jobCode=" + jobCode+"&batchCode="+batchCode+"&type="+type+"&sendServer="+sendServer;
                $.ajax({
                    type: "GET",
                    url: url,
                    contentType: "application/json; charset=utf-8",
                    async: false,
                    dataType: "json",
                    success: function (result) {
                        console.log("结果：========",result);
                        if (result.returnCode == "0") {
                            layer.msg("撤回成功");
                        }else {
                            layer.msg("撤回失败："+result.msg);
                        }
                    },
                    error:function (result) {
                        layer.msg("撤回失败："+result.msg);
                    }

                });
            },
            //获取工资表名 下拉列表
            getSalaryTable:function () {
                var self = this;
                var url = basePath + "salarySheet/getSearchData";

                $.ajax({
                    type: "POST",
                    url: url,
                    contentType: "application/json; charset=utf-8",
                    async: false,
                    dataType: "json",
                    success: function (result) {

                        if (result.returnCode == "0") {
                            console.log("下拉数据：========",result);
                            self.salaryTableNameList = result.data;
                            console.log(self.salaryTableNameList);
                        }else {
                            layer.msg(result.msg);
                        }
                    }

                });
            }

        },
        mounted:function(){
            this.init();
        }
    });
});
//














